home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / Drop•MPSR ƒ / DropShell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  6.6 KB  |  284 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DropShell.c
  5. **
  6. **   Description:    Main application code for the QuickShell
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Author    Description
  23. **    ---------    ------    ---------------------------------------------
  24. **    23 Jun    94    LDR        Implemented support for disk insertion events
  25. **    02 Feb    94    LDR        Updated for Final SDK & CodeWarrior a2
  26. **                        Removed the ResumeProc as per new Apple recommendations
  27. **    11 Dec 93    SCS        Universal Headers/UPPs (Phoenix 68k/PPC & PPCC)
  28. **                        Skipped System 6 compatible rev of DropShell source
  29. **    09 Dec 91    LDR        Added support for new "Select File…" menu item
  30. **                        Quit now sends AEVT to self to be politically correct
  31. **                        Added support for the new gSplashScreen
  32. **    24 Nov 91    LDR        Added support for the Apple Menu (duh!)
  33. **    29 Oct 91    SCS        Changes for THINK C 5
  34. **    28 Oct 91    LDR        Officially renamed DropShell (from QuickShell)
  35. **                        Added a bunch of comments for clarification
  36. **    06 Oct 91    MTC        Converted to MPW C
  37. **    09 Apr 91    LDR        Added to Projector
  38. **
  39. ******************************************************************************/
  40.  
  41. #ifndef __MWERKS__
  42. #include <Desk.h>
  43. #include <Dialogs.h>
  44. #include <Errors.h>
  45. #include <Files.h>
  46. #include <Fonts.h>
  47. #include <Memory.h>
  48. #include <Menus.h>
  49. #include <StandardFile.h>
  50. #include <TextEdit.h>
  51. #include <Types.h>
  52. #include <Windows.h>
  53. #endif
  54.  
  55. #include "DSGlobals.h"
  56. #include "DSUserProcs.h"
  57. #include "DSAppleEvents.h"
  58.  
  59. #include "DropShell.h"
  60.  
  61.  
  62.  
  63. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent;
  64. EventRecord    gEvent;
  65. MenuHandle    gAppleMenu, gFileMenu;
  66. WindowPtr    gSplashScreen;
  67.  
  68. #ifdef MPW
  69. extern void _DataInit();    
  70. #endif
  71.  
  72.  
  73. #pragma segment Initialize
  74. void InitToolbox (void) 
  75. {
  76.  
  77. #ifdef MPW
  78.     UnloadSeg ((Ptr) _DataInit );
  79. #endif
  80.  
  81.     InitGraf ( &qd.thePort );
  82.     InitFonts ();
  83.     InitWindows ();
  84.     InitMenus ();
  85.     TEInit ();
  86.     InitDialogs (NULL);        // use of ResumeProcs no longer approved by Apple
  87.     InitCursor ();
  88.     FlushEvents ( everyEvent, 0 );
  89.     
  90.     // how about some memory fun! Two should be enough!
  91.     MoreMasters ();
  92.     MoreMasters ();
  93.     }
  94.  
  95. /*
  96.     Let's setup those global variables that the DropShell uses.
  97.     
  98.     If you add any globals for your own use,
  99.     init them in the InitUserGlobals routine in DSUserProcs.c
  100. */
  101. #pragma segment Initialize
  102. Boolean InitGlobals (void) 
  103. {
  104.     long aLong;
  105.  
  106.     gDone            = false;
  107.     gOApped            = false;    // probably not since users are supposed to DROP things!
  108.     gHasAppleEvents    = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
  109.     gSplashScreen    = NULL;
  110.  
  111.     return(InitUserGlobals());    // call the user proc
  112. }
  113.  
  114. /*
  115.     Again, nothing fancy.  Just setting up the menus.
  116.     
  117.     If you add any menus to your DropBox - insert them here!
  118. */
  119. #pragma segment Initialize
  120. void SetUpMenus (void) {
  121.  
  122.     gAppleMenu = GetMenu ( kAppleNum );
  123.     AddResMenu ( gAppleMenu, 'DRVR' );
  124.     InsertMenu ( gAppleMenu, 0 );
  125.  
  126.     gFileMenu = GetMenu ( kFileNum );
  127.     InsertMenu ( gFileMenu, 0 );
  128.     DrawMenuBar ();
  129. }
  130.  
  131. /*
  132.     This routine is called during startup to display a splash screen.
  133.     
  134.     This was recommend by the Blue Team HI person, John Sullivan, who
  135.     feels that all apps should display something so that users can easily
  136.     tell what is running, and be able to switch by clicking.  Thanks John!
  137. */
  138. #pragma segment Initialize
  139. void InstallSplashScreen(void) 
  140. {
  141.     #define windowPicID    128
  142.  
  143.     PicHandle    picH;
  144.  
  145.     if (!gSplashScreen) {  // show the splash screen window
  146.         picH = GetPicture(windowPicID);
  147.         if (picH) {
  148.             gSplashScreen = GetNewWindow(windowPicID, NULL, (WindowPtr)-1L);
  149.             if (gSplashScreen) {
  150.                 SetWindowPic(gSplashScreen, picH);
  151.                 // Don't show it here, since we only want to it for oapp launches!
  152.                 // ShowWindow(gSplashScreen);
  153.             }
  154.         }
  155.     }
  156. }
  157.  
  158.  
  159. /*    --------------- Standard Event Handling routines ---------------------- */
  160. #pragma segment Main
  161. void ShowAbout () {
  162.     (void) Alert ( 128, NULL );
  163.     }
  164.  
  165.  
  166. #pragma segment Main
  167. void DoMenu ( long retVal ) {
  168.     short    menuID, itemID;
  169.     Str255    itemStr;
  170.  
  171.     menuID = HiWord ( retVal );
  172.     itemID = LoWord ( retVal );
  173.     
  174.     switch ( menuID ) {
  175.         case kAppleNum:
  176.             if ( itemID == 1 )
  177.                 ShowAbout ();    /*    Show the about box */
  178.             else
  179.             {
  180.                 GetItem(GetMHandle(kAppleNum), itemID, itemStr);
  181.                 OpenDeskAcc(itemStr);
  182.             }
  183.             break;
  184.             
  185.         case kFileNum:
  186.             if ( itemID == 1 )
  187.                 SelectFile();        // call file selection userProc
  188.             else
  189.                 SendQuitToSelf();    // send self a 'quit' event
  190.             break;
  191.         
  192.         default:
  193.             break;
  194.             
  195.         }
  196.     HiliteMenu(0);        // turn it off!
  197.     }
  198.  
  199.  
  200. #pragma segment Main
  201. void DoMouseDown ( EventRecord *curEvent ) {
  202.     WindowPtr    whichWindow;
  203.     short        whichPart;
  204.  
  205.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  206.     switch ( whichPart ) {
  207.         case inMenuBar:
  208.             DoMenu ( MenuSelect ( curEvent->where ));
  209.             break;
  210.         
  211.         case inSysWindow:
  212.             SystemClick ( curEvent, whichWindow );
  213.             break;
  214.         
  215.         case inDrag:
  216.             {
  217.                 Rect    boundsRect = (*GetGrayRgn())->rgnBBox;
  218.                 DragWindow ( whichWindow, curEvent->where, &boundsRect );
  219.             }
  220.         default:
  221.             break;
  222.         }
  223.     }
  224.  
  225.  
  226. #pragma segment Main
  227. void DoKeyDown ( EventRecord *curEvent ) {
  228.     if ( curEvent->modifiers & cmdKey )
  229.         DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
  230.     }
  231.  
  232.  
  233.  
  234. #pragma segment Main
  235. void main ( ) 
  236. {
  237.  
  238.     InitToolbox ();
  239.     if ( InitGlobals () ) {    // if we succeeding in initting self
  240.         if ( !gHasAppleEvents )
  241.             ErrorAlert ( kErrStringID, kCantRunErr, 0 );
  242.         else {
  243.             InitAEVTStuff ();
  244.             SetUpMenus ();
  245.             InstallSplashScreen ();
  246.             
  247.             while ( !gDone ) {
  248.                 gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  249.                 if ( gWasEvent ) {
  250.                     switch ( gEvent.what ) {
  251.                         case kHighLevelEvent:
  252.                             DoHighLevelEvent ( &gEvent );
  253.                             break;
  254.                             
  255.                         case mouseDown:
  256.                             DoMouseDown ( &gEvent );
  257.                             break;
  258.                             
  259.                         case keyDown:
  260.                         case autoKey:
  261.                             DoKeyDown ( &gEvent );
  262.                             break;
  263.  
  264.                         case diskEvt:
  265.                             if (HiWord(gEvent.message)) {
  266.                                 Point diskInitPt;
  267.                                 
  268.                                 diskInitPt.v = diskInitPt.h = 100;
  269.                                 DILoad();
  270.                                 DIBadMount(diskInitPt, gEvent.message);
  271.                                 DIUnload();
  272.                             }
  273.                             break;
  274.                             
  275.                         default:
  276.                             break;
  277.                     }
  278.                 }
  279.             }
  280.         }
  281.         DisposeUserGlobals();    // call the userproc to clean itself up
  282.     }
  283. }
  284.